# import keyword
# print(keyword.kwlist)
#
#
# if True:
#     print ("Answer")
#     print ("True")
# else:
#     print ("Answer")
 # print ("False")    # 缩进不一致，会导致运行错误

# item_one = 1
# item_two = 2
# item_three = 3
# total = item_one + \
#         item_two + \
#         item_three
# print(total)  # 输出为 6

# item_one = 1
# item_two = 2
# item_three = 3
# total = [item_one + item_two + item_three]
# print(total)  # 输出为 6
# total = (item_one + item_two + item_three)
# print(total)  # 输出为 6
# total = {item_one + item_two + item_three}
# print(total)  # 输出为 6

# str = '123456789'
#
# print(str)  # 输出字符串
# print(str[0:-1])  # 输出第一个到倒数第二个的所有字符
# print(str[0])  # 输出字符串第一个字符
# print(str[2:5])  # 输出从第三个开始到第六个的字符（不包含）
# print(str[2:])  # 输出从第三个开始后的所有字符
# print(str[1:5:2])  # 输出从第二个开始到第五个且每隔一个的字符（步长为2）
# print(str * 2)  # 输出字符串两次
# print(str + '你好')  # 连接字符串
#
# print('------------------------------')
#
# print('hello\nrunoob')  # 使用反斜杠(\)+n转义特殊字符
# print(r'hello\nrunoob')  # 在字符串前面添加一个 r，表示原始字符串，不会发生转义


# input("\n\n按下 enter 键后退出。")

# x = "a"
# y = "b"
# # 换行输出
# print(x)
# print(y)
#
# print('---------')
# # 不换行输出
# print(x, end=" ")
# print(y, end=" ")
# print()


# import sys
# print('================Python import mode==========================')
# print ('命令行参数为:')
# for i in sys.argv:
#     print (i)
# print ('\n python 路径为',sys.path)
#
# from sys import argv, path  # 导入特定的成员
#
# print('================python from import===================================')
# print('path:', path)  # 因为已经导入path成员，所以此处引用时不需要加sys.path

# counter = 100          # 整型变量
# miles   = 1000.0       # 浮点型变量
# name    = "runoob"     # 字符串
#
# print (counter)
# print (miles)
# print (name)

# # 变量定义
# x = 10          # 整数
# y = 3.14         # 浮点数
# name = "Alice"   # 字符串
# is_active = True # 布尔值
#
# # 多变量赋值
# a, b, c = 1, 2, "three"
#
# # 查看数据类型
# print(type(x))        # <class 'int'>
# print(type(y))        # <class 'float'>
# print(type(name))     # <class 'str'>
# print(type(is_active)) # <class 'bool'>


# a, b, c, d = 20, 5.5, True, 4+3j
# print(type(a), type(b), type(c), type(d))
# print(isinstance(a, int))

# 1 is True
# 0 is False


# a = 10
# b = 20
# del a
# print(b)

# str = 'Runoob'  # 定义一个字符串变量
#
# print(str)           # 打印整个字符串
# print(str[0:-1])     # 打印字符串第一个到倒数第二个字符（不包含倒数第一个字符）
# print(str[0])        # 打印字符串的第一个字符
# print(str[2:5])      # 打印字符串第三到第五个字符（不包含索引为 5 的字符）
# print(str[2:])       # 打印字符串从第三个字符开始到末尾
# print(str * 2)       # 打印字符串两次
# print(str + "TEST")  # 打印字符串和"TEST"拼接在一起
# print('Ru\noob')
# print(r'Ru\noob')


# # 布尔类型的值和类型
# a = True
# b = False
# print(type(a))  # <class 'bool'>
# print(type(b))  # <class 'bool'>
#
# # 布尔类型的整数表现
# print(int(True))  # 1
# print(int(False))  # 0
#
# # 使用 bool() 函数进行转换
# print(bool(0))  # False
# print(bool(42))  # True
# print(bool(''))  # False
# print(bool('Python'))  # True
# print(bool([]))  # False
# print(bool([1, 2, 3]))  # True
#
# # 布尔逻辑运算
# print(True and False)  # False
# print(True or False)  # True
# print(not True)  # False
#
# # 布尔比较运算
# print(5 > 3)  # True
# print(2 == 2)  # True
# print(7 < 4)  # False
#
# # 布尔值在控制流中的应用
# if True:
#     print("This will always print")
#
# if not False:
#     print("This will also always print")
#
# x = 10
# if x:
#     print("x is non-zero and thus True in a boolean context")


# list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]  # 定义一个列表
# tinylist = [123, 'runoob']
#
# print (list)            # 打印整个列表
# print (list[0])         # 打印列表的第一个元素
# print (list[1:3])       # 打印列表第二到第四个元素（不包含第四个元素）
# print (list[2:])        # 打印列表从第三个元素开始到末尾
# print (tinylist * 2)    # 打印tinylist列表两次
# print (list + tinylist)  # 打印两个列表拼接在一起的结果


# def reverseWords(input):
#     # 通过空格将字符串分隔符，把各个单词分隔为列表
#     inputWords = input.split(" ")
#
#     # 翻转字符串
#     # 假设列表 list = [1,2,3,4],
#     # list[0]=1, list[1]=2 ，而 -1 表示最后一个元素 list[-1]=4 ( 与 list[3]=4 一样)
#     # inputWords[-1::-1] 有三个参数
#     # 第一个参数 -1 表示最后一个元素
#     # 第二个参数为空，表示移动到列表末尾
#     # 第三个参数为步长，-1 表示逆向
#     inputWords = inputWords[-1::-1]
#
#     # 重新组合字符串
#     output = ' '.join(inputWords)
#
#     return output
#
#
# if __name__ == "__main__":
#     input = 'I like runoob'
#     rw = reverseWords(input)
#     print(rw)


# tuple = ( 'abcd', 786 , 2.23, 'runoob', 70.2  )
# tinytuple = (123, 'runoob')
#
# print (tuple)             # 输出完整元组
# print (tuple[0])          # 输出元组的第一个元素
# print (tuple[1:3])        # 输出从第二个元素开始到第三个元素
# print (tuple[2:])         # 输出从第三个元素开始的所有元素
# print (tinytuple * 2)     # 输出两次元组
# print (tuple + tinytuple) # 连接元组


# sites = {'Google', 'Taobao', 'Runoob', 'Facebook', 'Zhihu', 'Baidu'}
#
# print(sites)   # 输出集合，重复的元素被自动去掉
#
# # 成员测试
# if 'Runoob' in sites :
#     print('Runoob 在集合中')
# else :
#     print('Runoob 不在集合中')
#
# # set可以进行集合运算
# a = set('abracadabra')
# b = set('alacazam')
#
# print(a)
#
# print(a - b)     # a 和 b 的差集
#
# print(a | b)     # a 和 b 的并集
#
# print(a & b)     # a 和 b 的交集
#
# print(a ^ b)     # a 和 b 中不同时存在的元素

# dict = {}
# dict['one'] = "1 - 菜鸟教程"
# dict[2]     = "2 - 菜鸟工具"
#
# tinydict = {'name': 'runoob','code':1, 'site': 'www.runoob.com'}
#
#
# print (dict['one'])       # 输出键为 'one' 的值
# print (dict[2])           # 输出键为 2 的值
# print (tinydict)          # 输出完整的字典
# print (tinydict.keys())   # 输出所有键
# print (tinydict.values()) # 输出所有值

# mydict = dict([('Runoob', 1), ('Google', 2), ('Taobao', 3)])
# print(mydict)

# num_int = 123
# num_flo = 1.23
#
# num_new = num_int + num_flo
#
# print("num_int 数据类型为:",type(num_int))
# print("num_flo 数据类型为:",type(num_flo))
#
# print("num_new 值为:",num_new)
# print("num_new 数据类型为:",type(num_new))


# num_int = 123
# num_str = "456"
#
# print("num_int 数据类型为:",type(num_int))
# print("类型转换前，num_str 数据类型为:",type(num_str))
#
# num_str = int(num_str)    # 强制转换为整型
# print("类型转换后，num_str 数据类型为:",type(num_str))
#
# num_sum = num_int + num_str
#
# print("num_int 与 num_str 相加结果为:",num_sum)
# print("sum 数据类型为:",type(num_sum))


# a = 21
# b = 10
# c = 0
#
# c = a + b
# print("1 - c 的值为：", c)
#
# c = a - b
# print("2 - c 的值为：", c)
#
# c = a * b
# print("3 - c 的值为：", c)
#
# c = a / b
# print("4 - c 的值为：", c)
#
# c = a % b
# print("5 - c 的值为：", c)
#
# # 修改变量 a 、b 、c
# a = 2
# b = 3
# c = a ** b
# print("6 - c 的值为：", c)
#
# a = 10
# b = 5
# c = a // b
# print("7 - c 的值为：", c)


# a = 21
# b = 10
# c = 0
#
# if (a == b):
#     print("1 - a 等于 b")
# else:
#     print("1 - a 不等于 b")
#
# if (a != b):
#     print("2 - a 不等于 b")
# else:
#     print("2 - a 等于 b")
#
# if (a < b):
#     print("3 - a 小于 b")
# else:
#     print("3 - a 大于等于 b")
#
# if (a > b):
#     print("4 - a 大于 b")
# else:
#     print("4 - a 小于等于 b")
#
# # 修改变量 a 和 b 的值
# a = 5
# b = 20
# if (a <= b):
#     print("5 - a 小于等于 b")
# else:
#     print("5 - a 大于  b")
#
# if (b >= a):
#     print("6 - b 大于等于 a")
# else:
#     print("6 - b 小于 a")

# a = 20
# b = 20
#
# if (a is b):
#     print("1 - a 和 b 有相同的标识")
# else:
#     print("1 - a 和 b 没有相同的标识")
#
# if (id(a) == id(b)):
#     print("2 - a 和 b 有相同的标识")
# else:
#     print("2 - a 和 b 没有相同的标识")
#
# # 修改变量 b 的值
# b = 30
# if (a is b):
#     print("3 - a 和 b 有相同的标识")
# else:
#     print("3 - a 和 b 没有相同的标识")
#
# if (a is not b):
#     print("4 - a 和 b 没有相同的标识")
# else:
#     print("4 - a 和 b 有相同的标识")


# a = 20
# b = 10
# c = 15
# d = 5
# e = 0
#
# e = (a + b) * c / d  # ( 30 * 15 ) / 5
# print("(a + b) * c / d 运算结果为：", e)
#
# e = ((a + b) * c) / d  # (30 * 15 ) / 5
# print("((a + b) * c) / d 运算结果为：", e)
#
# e = (a + b) * (c / d)  # (30) * (15/5)
# print("(a + b) * (c / d) 运算结果为：", e)
#
# e = a + (b * c) / d  # 20 + (150/5)
# print("a + (b * c) / d 运算结果为：", e)

# import time
#
# for i in range(101): # 添加进度条图形和百分比
#     bar = '[' + '=' * (i // 2) + ' ' * (50 - i // 2) + ']'
#     print(f"\r{bar} {i:3}%", end='', flush=True)
#     time.sleep(0.05)
# print()

# for i in range(1, 101):
#     print(i)

# # Fibonacci series: 斐波纳契数列
# # 两个元素的总和确定了下一个数
# a, b = 0, 1
# while b < 10:
#     print(b)
#     a, b = b, a+b

# n = 10
# a, b = 0, 1
# for i in range(n):
#     print(b)
#     a, b = b, a + b

# # Fibonacci series: 斐波纳契数列
# # 两个元素的总和确定了下一个数
# a, b = 0, 1
# while b < 1000:
#     print(b, end=',')
#     a, b = b, a+b

# names = ['Bob','Tom','alice','Jerry','Wendy','Smith']
# new_names = [name.upper()for name in names if len(name)>3]
# print(new_names)

# multiples = [i for i in range(30) if i % 3 == 0]
# print(multiples)

# listdemo = ['Google','Runoob', 'Taobao']
# # 将列表中各字符串值为键，各字符串的长度为值，组成键值对
# newdict = {key:len(key) for key in listdemo}
# print(newdict)

# dic = {x: x**2 for x in (2, 4, 6)}
# print(dic)

# a = {x for x in 'abracadabra' if x not in 'abc'}
# print(a)

# a = (x for x in range(1,10))
# print(a)
# print(tuple(a))

# list=[1,2,3,4]
# it = iter(list)
# print (next(it))
# print (next(it))


# list=[1,2,3,4]
# it = iter(list)    # 创建迭代器对象
# for x in it:
#     print (x, end=" ")


# import sys  # 引入 sys 模块
#
# list = [1, 2, 3, 4]
# it = iter(list)  # 创建迭代器对象
#
# while True:
#     try:
#         print(next(it))
#     except StopIteration:
#         sys.exit()

# class MyNumbers:
#     def __iter__(self):
#         self.a = 1
#         return self
#
#     def __next__(self):
#         x = self.a
#         self.a += 1
#         return x
#
#
# myclass = MyNumbers()
# myiter = iter(myclass)
#
# print(next(myiter))
# print(next(myiter))
# print(next(myiter))
# print(next(myiter))
# print(next(myiter))


# class MyNumbers:
#     def __iter__(self):
#         self.a = 1
#         return self
#
#     def __next__(self):
#         if self.a <= 20:
#             x = self.a
#             self.a += 1
#             return x
#         else:
#             raise StopIteration
#
#
# myclass = MyNumbers()
# myiter = iter(myclass)
#
# for x in myiter:
#     print(x)


# def countdown(n):
#     while n > 0:
#         yield n
#         n -= 1
#
#
# # 创建生成器对象
# generator = countdown(5)
#
# # 通过迭代生成器获取值
# print(next(generator))  # 输出: 5
# print(next(generator))  # 输出: 4
# print(next(generator))  # 输出: 3
#
# # 使用 for 循环迭代生成器
# for value in generator:
#     print(value)  # 输出: 2 1


# import sys
#
#
# def fibonacci(n):  # 生成器函数 - 斐波那契
#     a, b, counter = 0, 1, 0
#     while True:
#         if (counter > n):
#             return
#         yield a
#         a, b = b, a + b
#         counter += 1
#
#
# f = fibonacci(10)  # f 是一个迭代器，由生成器返回生成
#
# while True:
#     try:
#         print(next(f), end=" ")
#     except StopIteration:
#         sys.exit()


# # 计算面积函数
# def area(width, height):
#     return width * height
#
#
# def print_welcome(name):
#     print("Welcome", name)
#
#
# print_welcome("Runoob")
# w = 4
# h = 5
# print("width =", w, " height =", h, " area =", area(w, h))

# # 定义函数
# def printme(str):
#     # 打印任何传入的字符串
#     print(str)
#     return
#
#
# # 调用函数
# printme("我要调用用户自定义函数!")
# printme("再次调用同一函数")

# def change(a):
#     print(id(a))  # 指向的是同一个对象
#     a = 10
#     print(id(a))  # 一个新对象
#
#
# a = 1
# print(id(a))
# change(a)

# # 可写函数说明
# def changeme(mylist):
#     "修改传入的列表"
#     mylist.append([1, 2, 3, 4])
#     print("函数内取值: ", mylist)
#     return
#
#
# # 调用changeme函数
# mylist = [10, 20, 30]
# changeme(mylist)
# print("函数外取值: ", mylist)


# # 可写函数说明
# def printme(str):
#     "打印任何传入的字符串"
#     print(str)
#     return
#
#
# # 调用 printme 函数，不加参数会报错
# printme()


# # 可写函数说明
# def printme(str):
#     "打印任何传入的字符串"
#     print(str)
#     return
#
#
# # 调用printme函数
# printme(str="菜鸟教程")

# 可写函数说明
# def printinfo(name, age):
#     "打印任何传入的字符串"
#     print("名字: ", name)
#     print("年龄: ", age)
#     return
#
#
# # 调用printinfo函数
# printinfo(age=50, name="runoob")

# # 可写函数说明
# def printinfo(name, age=35):
#     "打印任何传入的字符串"
#     print("名字: ", name)
#     print("年龄: ", age)
#     return
#
#
# # 调用printinfo函数
# printinfo(age=50, name="runoob")
# print("------------------------")
# printinfo(name="runoob")

# 可写函数说明
# def printinfo(arg1, *vartuple):
#     "打印任何传入的参数"
#     print("输出: ")
#     print(arg1)
#     print(vartuple)
#
#
# # 调用printinfo 函数
# printinfo(70, 60, 50)

# # 可写函数说明
# def printinfo(arg1, *vartuple):
#     "打印任何传入的参数"
#     print("输出: ")
#     print(arg1)
#     for var in vartuple:
#         print(var)
#     return
#
#
# # 调用printinfo 函数
# printinfo(10)
# printinfo(70, 60, 50)


# # 可写函数说明
# def printinfo(arg1, **vardict):
#     "打印任何传入的参数"
#     print("输出: ")
#     print(arg1)
#     print(vardict)
#
#
# # 调用printinfo 函数
# printinfo(1, a=2, b=3)

# def myfunc(n):
#     return lambda a: a * n
#
#
# mydoubler = myfunc(2)
# mytripler = myfunc(3)
#
# print(mydoubler(11))
# print(mytripler(11))


# # 可写函数说明
# def sum(arg1, arg2):
#     # 返回2个参数的和."
#     total = arg1 + arg2
#     print("函数内 : ", total)
#     return total
#
#
# # 调用sum函数
# total = sum(10, 20)
# print("函数外 : ", total)

# class Stack:
#     def __init__(self):
#         self.stack = []
#
#     def push(self, item):
#         self.stack.append(item)
#
#     def pop(self):
#         if not self.is_empty():
#             return self.stack.pop()
#         else:
#             raise IndexError("pop from empty stack")
#
#     def peek(self):
#         if not self.is_empty():
#             return self.stack[-1]
#         else:
#             raise IndexError("peek from empty stack")
#
#     def is_empty(self):
#         return len(self.stack) == 0
#
#     def size(self):
#         return len(self.stack)
#
# # 使用示例
# stack = Stack()
# stack.push(1)
# stack.push(2)
# stack.push(3)
#
# print("栈顶元素:", stack.peek())  # 输出: 栈顶元素: 3
# print("栈大小:", stack.size())    # 输出: 栈大小: 3
#
# print("弹出元素:", stack.pop())  # 输出: 弹出元素: 3
# print("栈是否为空:", stack.is_empty())  # 输出: 栈是否为空: False
# print("栈大小:", stack.size())    # 输出: 栈大小: 2\


# class Queue:
#     def __init__(self):
#         self.queue = []
#
#     def enqueue(self, item):
#         self.queue.append(item)
#
#     def dequeue(self):
#         if not self.is_empty():
#             return self.queue.pop(0)
#         else:
#             raise IndexError("dequeue from empty queue")
#
#     def peek(self):
#         if not self.is_empty():
#             return self.queue[0]
#         else:
#             raise IndexError("peek from empty queue")
#
#     def is_empty(self):
#         return len(self.queue) == 0
#
#     def size(self):
#         return len(self.queue)
#
# # 使用示例
# queue = Queue()
# queue.enqueue('a')
# queue.enqueue('b')
# queue.enqueue('c')
#
# print("队首元素:", queue.peek())    # 输出: 队首元素: a
# print("队列大小:", queue.size())    # 输出: 队列大小: 3
#
# print("移除的元素:", queue.dequeue())  # 输出: 移除的元素: a
# print("队列是否为空:", queue.is_empty())  # 输出: 队列是否为空: False
# print("队列大小:", queue.size())    # 输出: 队列大小: 2

# print([str(round(355/113, i)) for i in range(1, 6)])

# if __name__ == '__main__':
#    print('程序自身在运行')
# else:
#    print('我来自另一模块')

# def greet():
# print("来自 example 模块的问候！")
#
#
# if __name__ == "__main__":
#    print("该脚本正在直接运行。")
#    greet()
# else:
#    print("该脚本作为模块被导入。")
#


# class Test:
#    def prt(self):
#       print(self)
#       print(self.__class__)
#
#
# t = Test()
# t.prt()